﻿

$(function () {
    $("#sbiframe").load(function () {
        $(this).ready(function () {
            setTimeout(function () {
                document.domain = "localhost";
                var data = $("#sbiframe").contents().find("body").text();
                if (data != null) { alert("返回成功3:" + data); }
            }, 5000);

        });
    });
    var accountformat = /^[a-zA-Z0-9]*$/;
    var pwformat = /^(\w){6,20}$/;

    $(".verify_img").click(function () {
        getverfiy();
    })
    $("#sumbtn").click(function () {

        var val1 = $("form input").eq(0).val(); //账号
        var val2 = $("form input").eq(1).val(); // 密码
        var val3 = $("form input").eq(3).val(); // 验证码
        if ((val1 != "" && val1 != "用户账号") && (val2 != "" && val2 != "输入密码") && $("#txtTip").css("display") == "none") {
            if (val3.length == 4) {
                $(".verify").hide();
                return true;
            }
            else {
                if (val1.length < 6 || val1.length > 20 || !val1.match(accountformat)) { $("#txtTip").html("账号不正确！").show(); return false; } else {
                    if (val2.length < 6 || val2.length > 30 || !val2.match(pwformat)) { $("#txtTip").html("密码不正确！").show(); return false; } else {
                        $("#verify").show();
                        return false;
                    }
                }
            }
        }
        else {

            $("#txtTip").html("请填写完整再试！").show();
            return false;
        }
    });
    $(".inputwh").focus(function () {
        $("#txtTip").hide();
    });
    var cookie = $.cookies.get("error");
    if (cookie && cookie != "") {
        switch (cookie) {
            case "login0000": $("#txtTip").html("未填写验证码").show(); break;
            case "login0001": $("#txtTip").html("验证码不正确，请重试").show(); break;
            case "login0004": $("#txtTip").html("账号或者密码不正确，请重试").show(); break;
            default: $("#txtTip").html("填写的验证码不正确，请重试").show(); break;
        };
        $.cookies.del("error");
    };


    $(".logout").click(function () {
        $.ajax({
            url: "http://localhost:3295/account/logout",
            dataType: "jsonp",
            data: {},
            //jsonp: "jsoncallback",
            jsonpCallback: "jsoncallback",
            success: function (data) {
                var json = $.parseJSON(data);
                alert(json.code);
                window.location.reload();
            },
            error: function (data, textStatus) {
                var s = "";
                for (var property in data) {
                    s = s + "\n " + property + ": " + data[property];
                }

                window.location.reload();
            }
        });

    })

})
